//
//  GCW_AllTypeViewCell.m
//  MooMusic
//
//  Created by 管晨雯 on 15/10/26.
//  Copyright © 2015年 wjy. All rights reserved.
//

#import "GCW_AllTypeViewCell.h"
// 导入AllTypeCollectionViewCell的自定义cell头文件
#import "GCW_AllTypeCollectionViewCell.h"
@implementation GCW_AllTypeViewCell

static NSString *const cellCollection = @"cellCollection";

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatAllTypeUICollectionView];
    }
    return  self;
}

// 创建视图
- (void)creatSubAllTypeViews
{
    [self creatAllTypeUICollectionView];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (self.subArray.count > 0) {
        // 刷新collectionview
        [AllTypeCollectionView reloadData];
    }
}

// 创建collectionview
- (void)creatAllTypeUICollectionView
{
#pragma mark -- UICollectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // item大小 (宽  高)
    flowLayout.itemSize = CGSizeMake(SCREENWIDTH / 5.5, 50);
    // 最小的行间距 (垂直于滚动方向的是一行)
    flowLayout.minimumLineSpacing = 1;
    // 最小的列间距  cell的大小 section的缩进 共同来决定的item之间的距离
    flowLayout.minimumInteritemSpacing = 1;
    // 滚动方向 (纵向滚动)
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    // section的缩进 (上 左 下 右)
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
    
    AllTypeCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 130) collectionViewLayout:flowLayout];
    
    AllTypeCollectionView.backgroundColor =[UIColor whiteColor];
    
    AllTypeCollectionView.dataSource = self;
    AllTypeCollectionView.delegate = self;
    
    // 取消滑动
    AllTypeCollectionView.bounces = NO;
    
    // 注册item样式
    [AllTypeCollectionView registerClass:[GCW_AllTypeCollectionViewCell class] forCellWithReuseIdentifier:cellCollection];
    
    // 添加到父视图上
    [self.contentView addSubview:AllTypeCollectionView];
    
    
}

#pragma mark -- UICollectionViewDataSource
// 每个section中的item的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [self.TypeArr1 count];
}

// item重用池
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    GCW_AllTypeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellCollection forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor lightGrayColor];
    
    cell.label.text = [[self.TypeArr1 objectAtIndex:indexPath.item] valueForKey:@"name"];
    
    return cell;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
